package com.cloudptt.api.models.lbs;

public class LocationData {
	private double  lattitude  = 0;
	private int iLattitude  = 0;
	private double  longitude  = 0;
	private int iLongitude  = 0;
	private double  altitude = 0;
	private int iAltitude  = 0;

	private double bearing = 0;
	private int iBearing  = 0;
	private double speed = 0;
	private int iSpeed  = 0;
	
	public static LocationData getDefaultLocationData()
	{
		return new LocationData();
	}
	
	public LocationData(){}
	
	public LocationData(double lattitude,double longitude, double altitude,double bearing, double speed)
	{
		this.lattitude = lattitude;
		this.longitude = longitude;
		this.altitude = altitude;
		this.bearing = bearing;
		this.speed = speed;

		int[] encoded = Geo24BitConverter.encode(longitude, lattitude,altitude,bearing,speed);
		this.iLongitude = encoded[0];
		this.iLattitude = encoded[1];
		this.iAltitude = encoded[2];
		this.iBearing = encoded[3];
		this.iSpeed = encoded[4];
	}
	
	public boolean isValid()
	{
		if(this.lattitude != 0
				&& this.longitude != 0)
		{
			return true;
		}
		
		return false;
	}
	
//	public void updateLocationData(double lattitude,double longitude)
//	{
//		this.lattitude = lattitude;
//		this.longitude = longitude;
//	}
	
	public void updateLocationData(double lattitude,double longitude, double altitude,double bearing, double speed){
		this.lattitude = lattitude;
		this.longitude = longitude;
		this.altitude = altitude;
		this.bearing = bearing;
		this.speed = speed;

		int[] encoded = Geo24BitConverter.encode(longitude, lattitude,altitude,bearing,speed);
		this.iLongitude = encoded[0];
		this.iLattitude = encoded[1];
		this.iAltitude = encoded[2];
		this.iBearing = encoded[3];
		this.iSpeed = encoded[4];
	}

	public double getLattitude() {
		return lattitude;
	}

	public double getLongitude() {
		return longitude;
	}
	
	public double getAltitude(){
		return altitude;
	}
	
	public void setLattitude(double lattitude) {
		this.lattitude = lattitude;
	}
	public void setLongitude(double longitude) {
		this.longitude = longitude;
	}
	
	public void setAltitude(double altitude){
		this.altitude = altitude;
	}

	public String toString()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("<CurrentCoordinate>").append("\r\n");
		
		strBuff.append("<longitude type=\"Normal\">").append("\r\n");
		strBuff.append("<threebytes>").append(iLongitude).append("</threebytes>").append("\r\n");
		strBuff.append("</longitude>").append("\r\n");

		strBuff.append("<latitude type=\"Normal\">").append("\r\n");
		strBuff.append("<threebytes>").append(iLattitude).append("</threebytes>").append("\r\n");
		strBuff.append("</latitude>").append("\r\n");

		strBuff.append("<anyExt>").append("\r\n");
		strBuff.append("<altitude type=\"Normal\">").append("\r\n");
		strBuff.append("<twobytes>").append(iAltitude).append("</twobytes>").append("\r\n");
		strBuff.append("</altitude>").append("\r\n");
		strBuff.append("</anyExt>").append("\r\n");
		
		strBuff.append("</CurrentCoordinate>").append("\r\n");
//		strBuff.append(" lattitude = ").append(lattitude);
//		strBuff.append(" longitude = ").append(longitude);
//		strBuff.append(" height = ").append(altitude);
		return strBuff.toString();
	}

	public String toString2()
	{
		StringBuffer strBuff = new StringBuffer();
		strBuff.append("<CL_BearingAndSpeed type=\"Normal\">").append("\r\n");
		strBuff.append("<BearingAndSpeed>").append("22FFFFFFFFFFFF").append("</BearingAndSpeed>").append("\r\n");
		strBuff.append("<CL_BearingAndSpeed>").append("").append("</CL_BearingAndSpeed>").append("\r\n");
		strBuff.append("</CL_BearingAndSpeed>").append("\r\n");

		return strBuff.toString();
	}
}
